//
//  HRMainViewModel.m
//  Hear
//
//  Created by mac on 2017/4/7.
//  Copyright © 2017年 mac. All rights reserved.
//  点赞接口

#import "HRMainViewModel.h"
#import "HRMainRootModel.h"
#import "NSObject+YYModel.h"
@implementation HRMainViewModel

-(void)getGetSoundQuestionParent:(NSDictionary *)requstDict resultArr:(void(^)(NSArray *resultArr))resultArr{
    YTKApi *api = [YTKApi apiGetWithUrl:@"SoundInfo/Get_GetSoundQuestionParent" parameter:requstDict];
    [api getSuccessToken:^() {
        api.foceNoTocken = NO;
        [api setRequestSerializerType:YTKRequestSerializerTypeJSON];
        [api startWithCompletionBlockWithSuccess:^(__kindof YTKBaseRequest * _Nonnull request) {
            
            NSDictionary *dict = request.responseJSONObject;
            //            NSLog(@"拿到数据==============%@",[self getCurrentTime]);
            if ([dict[@"CodeStatus"] intValue] == 20000){
                NSArray *conentArr = [NSArray modelArrayWithClass:[HRHearTitleTypeModel class] json:dict[@"BodyContent"]];
                resultArr(conentArr);
            }else{
                resultArr(nil);
            }
        } failure:^(__kindof YTKBaseRequest * _Nonnull request) {
            resultArr(nil);
        }];
    }];
}

-(void)getMainContentParam:(HRMainRootRequestModel *)requestModel resultArr:(void(^)(NSArray *resultArr))resultArr
{
    NSString *url = @"";
//#if DEBUG
//    url = @"ContentManager/Get_GetSounds";
//#else
//    url = @"SoundInfo/Get_GetSounds";
//#endif
    url = @"SoundInfo/Get_GetSounds_";
    
    YTKApi *api = [YTKApi apiGetWithUrl:url parameter:requestModel];
//    NSLog(@"开始请求==============%@",[self getCurrentTime]);
    
    [api getSuccessToken:^() {
        api.foceNoTocken = NO;
        [api setRequestSerializerType:YTKRequestSerializerTypeJSON];
        [api startWithCompletionBlockWithSuccess:^(__kindof YTKBaseRequest * _Nonnull request) {
            
            NSDictionary *dict = request.responseJSONObject;
//            NSLog(@"拿到数据==============%@",[self getCurrentTime]);

            NSArray *conentArr = [NSArray modelArrayWithClass:[HRMainRootModel class] json:dict[@"BodyContent"]];
            
            for (HRMainRootModel *model in conentArr) {
                NSMutableArray *listSoundArr = [NSMutableArray array];
                for (id ListSoundJeson  in model.ListSound) {
                    HRMainRootModel *listSoundmodel = [HRMainRootModel modelWithJSON:ListSoundJeson];
                    [listSoundArr addObject:listSoundmodel];
                }
                model.ListSoundArr = listSoundArr;
            }
            
            resultArr(conentArr);
            
        } failure:^(__kindof YTKBaseRequest * _Nonnull request) {
            DDLog(@"SoundInfo/Get_GetSounds_  failed");
        }];
    }];
}


-(void)postSaveSoundLike:(NSDictionary *)requstDict isSeccess:(void(^)(BOOL isSeccess))isSeccess{
    YTKApi *api = [YTKApi apiPostWithUrl:@"MomentsInfo/Post_SaveMomentsLike" para:requstDict];
    [api getSuccessToken:^() {
        api.foceNoTocken = NO;
        [api setRequestSerializerType:YTKRequestSerializerTypeJSON];
        [api startWithCompletionBlockWithSuccess:^(__kindof YTKBaseRequest * _Nonnull request) {
            
            NSDictionary *dict = request.responseJSONObject;
            
            // BodyContent
            if ([dict[@"CodeStatus"] intValue] == 20000){
                isSeccess(YES);
            }else{
                isSeccess(NO);
            }
        } failure:^(__kindof YTKBaseRequest * _Nonnull request) {
            isSeccess(NO);
        }];
    }];
}




@end
